#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char a[30];
int b[30];
LL check(string s1,string s2,string s3)
{
	LL len=s1.size();
	LL cnt=s2.size();
	LL p=0;
	char c;
	for(LL i=0;i<len;i++)
	{
		if(p>s3.size()+1) return -1;
		if(p==0) c='0';
		else c=s3[p-1];
		for(LL j=0;j<cnt;j++)
		{
			if(s2[j]==c)
			{
				s2[j]='0';
			}
			if(s2[j]=='0')  continue;
			if(i>len-1) return -1;
			if(s1[i]!=s2[j]) return -1;
			i++;
		}
		i--;
		p++;
	}
	return 0;
}
int main()
{
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL t;cin>>t;
   while(t--)
   {
         memset(b,0,sizeof(b));
         memset(a,'\0',sizeof(a));
         string s1,s2,s3;
         cin>>s1;
         LL tot=1;
         LL len=s1.size();
         for(LL i=len-1;i>=0;i--)
         {
            LL ans=s1[i]-'a';
            if(b[ans]==0)
            {
                b[ans]++;
                a[tot++]=s1[i];
            }
            else b[ans]++;
        }
        LL ans=1,sum=0;
        for(LL i=tot-1;i>=1;i--)
        {
            LL tot=a[i]-'a';
            sum+=b[tot]/ans;
            s2+=a[i];
            ans++;
        }
        for(LL i=0;i<sum;i++) s3+=s1[i];
        if(check(s1,s3,s2)==-1) cout<<"-1"<<"\n";
        else {
            cout<<s3<<" "<<s2<<"\n";
        }
   }
}
